<%@page import="com.hhit.collaborative_learning.utils.Utils"%>
<%@page import="com.mysql.jdbc.StringUtils"%>
<%@page
	import="com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql"%>
<%@page import="com.hhit.collaborative_learning.entity.BlogPage"%>
<%@page import="com.hhit.collaborative_learning.entity.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String currentPageStr = request.getParameter("currentPage");
	String type = request.getParameter("type");
	if(StringUtils.isNullOrEmpty(type)){
		type="0";
	}
	String userId=Utils.getCookieValue("userId", request);
	PublicDaoImplMySql dao = new PublicDaoImplMySql();
	if(!StringUtils.isNullOrEmpty(userId)){
		BlogPage blogPage = dao.getBlogByUserIdTypeIsDelete(Integer.parseInt(userId),
				type, "0", currentPageStr);
		request.setAttribute("blogPage", blogPage);
	}
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="Stylesheet" href="<%=basePath%>css/main.css" />
<!--new top-->
<link rel="stylesheet" href="<%=basePath%>css/index.css">
<!--new top-->

<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jquery.cookie.js"></script>
<script type="text/javascript" src="<%=basePath%>js/csdn.js"></script>
<script type="text/javascript" src="<%=basePath%>js/master.js"></script>
<script type="text/javascript">
// 	var statichost = "http://static.blog.csdn.net";
		function setTop(blogId,type){
			if(type=='2'){
				alert("转载文章不能置顶!");
				return;
			}
			$.get("<%=basePath%>ManageBlogServlrt?action=1&blogId="+blogId,function(data,status){
				alert(data);
			});
		}
		
		function deleteBlog(blogId){
			if(confirm("删除文章将不可恢复，是否继续？")){
				$.get("<%=basePath%>ManageBlogServlrt?action=2&blogId="+blogId,function(data,status){
					location.href="<%=basePath%>learning/bloglist.jsp";
				});
			}
		}
</script>


<script type='text/javascript' src='<%=basePath%>js/postlist.js'></script>
</head>

<body>
	<!--new top-->
	<!--     <script id="toolbar-tpl-scriptId" fixed="true" prod="blog" skin="black" domain = "http://blog.csdn.net" src="http://static.csdn.net/public/common/toolbar/js/html.js" type="text/javascript"></script> -->
	<!--new top-->
	<div id="wrap">

		<div class="head">
			<div style="float:right; margin-top:20px; color:Red;"></div>
		</div>

		<div class="tabs_header">
			<ul id="ul_tab" class="tabs">
				<li><a href="bloglist.jsp"><span>文章管理</span></a></li>
				<li><a href="<%=basePath %>learning/manage_comment.jsp"><span>评论管理</span></a></li>
				<li><a href="<%=basePath %>learning/postedit.jsp"><span>发表文章</span></a></li>
				<li><a href="<%=basePath %>learning/draft.jsp"><span>草稿箱</span></a></li>
				<li><a href="<%=basePath %>learning/deleted.jsp"><span>回收站</span></a></li>
				<li><a href="<%=basePath %>learning/myattention.jsp"><span>我的关系</span></a></li>
				<c:if test="${cookie.cl_blogRight.value ne null}">
				<li><a href="<%=basePath %>learning/myright.jsp"><span>我的权限</span></a></li>
				</c:if>
			</ul>
		</div>
		<script type="text/javascript">
			setTab();
		</script>


		<div id="sel_div" class="h_status">
			<!-- 			类别：<select id="selCat"><option value="0">全部&nbsp;&nbsp;&nbsp;&nbsp;</option></select> -->
			类型：<select id="selType">
				<option value="0">全部&nbsp;&nbsp;&nbsp;&nbsp;</option>
				<option value="1">原创</option>
				<option value="2">转载</option>
				<option value="3">翻译</option></select>&nbsp;
		</div>
		
		<script type="text/javascript">
			$(document).ready(function(){
				$("#selType").val("<%=type%>"); 
			});
		</script>
		<!-- 		<table id="lstBox" cellspacing="0"> -->
		<!-- 			<tr> -->
		<!-- 				<th class="tdleft">标题</th> -->
		<!-- 				<th style="width:50px;">状态</th> -->
		<!-- 				<th style="width:50px;">阅读</th> -->
		<!-- 				<th style="width:50px;">评论</th> -->
		<!-- 				<th style="width:70px;">评论权限</th> -->
		<!-- 				<th style="width:170px;">操作</th> -->
		<!-- 			</tr> -->
		<!-- 			<tr> -->
		<!-- 				<td class='tdleft'><a -->
		<!-- 					href='http://blog.csdn.net/u013534446/article/details/45335513' -->
		<!-- 					target=_blank>JSP 文件上传</a><span class='gray'>（2015-04-28 -->
		<!-- 						14:18）</span></td> -->
		<!-- 				<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> -->
		<!-- 				<td>0</td> -->
		<!-- 				<td>0</td> -->
		<!-- 				<td><a href='?t=lock&id=45335513' class='lock'>禁止评论</a></td> -->
		<!-- 				<td><a href='/postedit/45335513'>编辑</a> | <a -->
		<!-- 					href='?t=top&id=45335513'>置顶</a> | <a href='?t=del&id=45335513' -->
		<!-- 					name=del>删除</a> | <a href='javascript:void(0);' -->
		<!-- 					onclick='javascript:return setcat(this,45335513);' class='cat'>分类</a></td> -->
		<!-- 			</tr> -->
		<!-- 		</table> -->
		<table id="lstBox" cellspacing="0">
			<tr>
				<th class="tdleft">标题</th>
				<th style="width:50px;">状态</th>
				<th style="width:50px;">阅读</th>
				<th style="width:50px;">评论</th>
				<th style="width:70px;">评论权限</th>
				<th style="width:170px;">操作</th>
			</tr>
			<c:forEach items="${requestScope.blogPage.list }" var="blog">
				<tr>
					<td class='tdleft'><a
						href='<%=basePath %>learning/article.jsp?userId=<%=userId %>&blogId=${blog.blogId}&blogName=${blog.blogName}'
						target=_blank>${blog.blogName}</a><span class='gray'>（${blog.time}）
							<c:if test="${blog.canComment eq 0 }">
								<i class='suo' title='该文章禁止评论'>锁</i>
							</c:if>
					</span></td>
					<c:choose>
						<c:when test="${blog.state eq 0}">
							<td>待审核</td>
						</c:when>
						<c:when test="${blog.state eq 1 }">
							<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
						</c:when>
						<c:otherwise>
							<td>审核 不通过</td>
						</c:otherwise>
					</c:choose>
					<td>${blog.readNum}</td>
					<td>${blog.commentNum }</td>
					<c:choose>
						<c:when test="${blog.canComment eq 0}">
							<td><a
								href='<%=basePath %>ManageBlogServlrt?action=4&blogId=${blog.blogId}'
								class='unlock'>允许评论</a></td>
						</c:when>
						<c:otherwise>
							<td><a
								href='<%=basePath %>ManageBlogServlrt?action=5&blogId=${blog.blogId}'
								class='lock'>禁止评论</a></td>
						</c:otherwise>
					</c:choose>
					<td><a href='<%=basePath %>learning/postedit.jsp?blogId=${blog.blogId}'>编辑</a> | <a onclick="setTop('${blog.blogId}','${blog.type}');return false;" href="#">置顶</a> | <a onclick="deleteBlog('${blog.blogId}')"
						href='#'
						name=del>删除</a> <!-- 					 | <a href='javascript:void(0);' --> <!-- 					onclick='javascript:return setcat(this,45335513);' class='cat'>分类</a> -->
					</td>
				</tr>
			</c:forEach>
		</table>

		<div class="page_nav">
			<span> ${requestScope.blogPage.count }条数据
									共${requestScope.blogPage.totalPage }页</span>
								<c:if test="${requestScope.blogPage.currentPage>1}">
									<a href="bloglist.jsp?type=<%=type %>&currentPage=1">首页</a>
									<a
										href="bloglist.jsp?type=<%=type %>&currentPage=${requestScope.blogPage.currentPage-1}">上一页</a>
								</c:if>
								<c:if test="${requestScope.blogPage.pageDiffer>0}">
									<a
										href="bloglist.jsp?type=<%=type %>&currentPage=${requestScope.blogPage.pageDiffer*5-4}">...</a>
								</c:if>

								<c:if
									test="${requestScope.blogPage.pageDiffer*5+1<=requestScope.blogPage.totalPage}">
									<c:choose>
										<c:when
											test="${requestScope.blogPage.currentPage==requestScope.blogPage.pageDiffer*5+1 }">
											<strong>${requestScope.blogPage.pageDiffer*5+1}</strong>
										</c:when>
										<c:otherwise>
											<a
												href="bloglist.jsp?type=<%=type %>&currentPage=${requestScope.blogPage.pageDiffer*5+1}">${requestScope.blogPage.pageDiffer*5+1}</a>
										</c:otherwise>
									</c:choose>
								</c:if>

								<c:if
									test="${requestScope.blogPage.pageDiffer*5+2<=requestScope.blogPage.totalPage}">
									<c:choose>
										<c:when
											test="${requestScope.blogPage.currentPage==requestScope.blogPage.pageDiffer*5+2 }">
											<strong>${requestScope.blogPage.pageDiffer*5+2}</strong>
										</c:when>
										<c:otherwise>
											<a
												href="bloglist.jsp?type=<%=type %>&currentPage=${requestScope.blogPage.pageDiffer*5+2}">${requestScope.blogPage.pageDiffer*5+2}</a>
										</c:otherwise>
									</c:choose>
								</c:if>

								<c:if
									test="${requestScope.blogPage.pageDiffer*5+3<=requestScope.blogPage.totalPage}">
									<c:choose>
										<c:when
											test="${requestScope.blogPage.currentPage==requestScope.blogPage.pageDiffer*5+3 }">
											<strong>${requestScope.blogPage.pageDiffer*5+3}</strong>
										</c:when>
										<c:otherwise>
											<a
												href="bloglist.jsp?type=<%=type %>&currentPage=${requestScope.blogPage.pageDiffer*5+3}">${requestScope.blogPage.pageDiffer*5+3}</a>
										</c:otherwise>
									</c:choose>
								</c:if>

								<c:if
									test="${requestScope.blogPage.pageDiffer*5+4<=requestScope.blogPage.totalPage}">
									<c:choose>
										<c:when
											test="${requestScope.blogPage.currentPage==requestScope.blogPage.pageDiffer*5+4 }">
											<strong>${requestScope.blogPage.pageDiffer*5+4}</strong>
										</c:when>
										<c:otherwise>
											<a
												href="bloglist.jsp?type=<%=type %>&currentPage=${requestScope.blogPage.pageDiffer*5+4}">${requestScope.blogPage.pageDiffer*5+4}</a>
										</c:otherwise>
									</c:choose>
								</c:if>

								<c:if
									test="${requestScope.blogPage.pageDiffer*5+5<=requestScope.blogPage.totalPage}">
									<c:choose>
										<c:when
											test="${requestScope.blogPage.currentPage==requestScope.blogPage.pageDiffer*5+5 }">
											<strong>${requestScope.blogPage.pageDiffer*5+5}</strong>
										</c:when>
										<c:otherwise>
											<a
												href="bloglist.jsp?type=<%=type %>&currentPage=${requestScope.blogPage.pageDiffer*5+5}">${requestScope.blogPage.pageDiffer*5+5}</a>
										</c:otherwise>
									</c:choose>
								</c:if>
								<c:if
									test="${requestScope.blogPage.totalPage>5 && requestScope.blogPage.pageDiffer<requestScope.blogPage.totalPage/5-1}">
									<a
										href="bloglist.jsp?type=<%=type %>&currentPage=${requestScope.blogPage.pageDiffer*5+6}">...</a>
								</c:if>
								<c:if
									test="${requestScope.blogPage.currentPage<requestScope.blogPage.totalPage}">
									<a
										href="bloglist.jsp?type=<%=type %>&currentPage=${requestScope.blogPage.currentPage+1}">下一页</a>
									<a
										href="bloglist.jsp?type=<%=type %>&currentPage=${requestScope.blogPage.totalPage}">尾页</a>
								</c:if>
		</div>

		<!-- 		<div id="setcat_div" style="display:none;"> -->
		<!-- 			<div class="frame"> -->
		<!-- 				<input name="close" type="button" class="close" -->
		<!-- 					onclick="cancel_cat()"> -->
		<!-- 				<div id="setcat_box"></div> -->
		<!-- 				<p style="text-align:center;"> -->
		<!-- 					<input type="button" value="确定" class="btn_01" onclick="save_cat()" /> -->
		<!-- 				</p> -->
		<!-- 			</div> -->
		<!-- 		</div> -->


		<script type="text/javascript">
			$(function() {
				$("#lstBox tr").each(function() {
					var tr = $(this);
					if (tr.text().indexOf("待审核") > -1) {
						var tds = $(tr.find("td")[5]);
						var a = $(tds.find("a"));
						a.each(function() {
							if ($(this).text().indexOf("置顶") > -1) {
								$(this).remove();
								tds.html(tds.html().replace("|  |", "|"));
							}
						});
					}
				});
				
			
			});
			
		</script>

	</div>

</body>
</html>

